package eg9_9;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;

public class JButtonDemo extends JFrame {
    private JTextField textField;
    private JButton button;
    public JButtonDemo(){
        textField = new JTextField();
        textField.setColumns(10);
        this.add(textField);
        button  = new JButton("Button");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                buttonAction();
            }
        });
        this.add(button);
        this.setLayout(new FlowLayout());
        this.setBounds(50,50,300,300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    private void buttonAction() {
        this.textField.setText("hello world");
    }
}
